<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>图片转视频展示页</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: "微软雅黑", sans-serif;
        }
        body {
            background-color: #f5f5f5;
            padding: 20px;
        }
        .container {
            max-width: 1200px;
            margin: 0 auto;
        }
        h1 {
            text-align: center;
            color: #333;
            margin: 20px 0 40px;
        }
        /* 图片网格布局（响应式） */
        .image-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
            gap: 20px;
        }
        .image-item {
            background: white;
            border-radius: 8px;
            overflow: hidden;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
            cursor: pointer;
            transition: transform 0.3s;
        }
        .image-item:hover {
            transform: translateY(-5px);
        }
        .image-item img {
            width: 100%;
            height: 180px;
            object-fit: cover; /* 保持图片比例，裁剪多余部分 */
        }
        .image-item p {
            padding: 15px;
            text-align: center;
            color: #555;
        }
        /* 视频弹窗（默认隐藏） */
        .video-modal {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.85);
            z-index: 999;
            display: none;
            justify-content: center;
            align-items: center;
            padding: 20px;
        }
        .video-container {
            width: 100%;
            max-width: 900px;
            position: relative;
        }
        .close-btn {
            position: absolute;
            top: -40px;
            right: 0;
            color: white;
            font-size: 30px;
            cursor: pointer;
        }
        .video-player {
            width: 100%;
            height: 500px;
            border-radius: 8px;
        }
        /* 适配手机 */
        @media (max-width: 768px) {
            .video-player {
                height: 300px;
            }
            .image-grid {
                grid-template-columns: repeat(2, 1fr);
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>点击图片播放对应视频</h1>
        
        <!-- 图片网格（8个图片） -->
        <div class="image-grid" id="imageGrid">
            <!-- 图片会通过JS动态生成 -->
        </div>

        <!-- 视频弹窗 -->
        <div class="video-modal" id="videoModal">
            <div class="video-container">
                <span class="close-btn" onclick="closeVideo()">&times;</span>
                <!-- 视频播放器 -->
                <iframe id="videoIframe" class="video-player" frameborder="0" allowfullscreen></iframe>
                <!-- 若用本地视频，替换上面的iframe为：
                <video id="videoPlayer" class="video-player" controls>
                    <source src="" type="video/mp4">
                </video>
                -->
            </div>
        </div>
    </div>

    <script>
        // 核心数据：8个图片和对应视频的信息（你只需修改这里的路径即可）
        const mediaData = [
            {
                image: "https://img.alicdn.com/imgextra/i3/3321175821/O1CN01edsqdm1ss4a36KGdw_!!3321175821.jpg", // 图片1路径
                video: "http://cloud.video.taobao.com/play/u/null/p/1/e/6/t/1/529628503031.mp4", // 视频1链接
                title: "视频1标题" // 图片下方的文字
            },
            {
                image: "https://picsum.photos/400/300?random=2", // 图片2路径
                video: "https://player.bilibili.com/player.html?bvid=BV1EJ411876S&page=1", // 视频2链接
                title: "视频2标题"
            },
            {
                image: "https://picsum.photos/400/300?random=3", // 图片3路径
                video: "https://player.bilibili.com/player.html?bvid=BV1QW411e7PL&page=1", // 视频3链接
                title: "视频3标题"
            },
            {
                image: "https://picsum.photos/400/300?random=4", // 图片4路径
                video: "https://player.bilibili.com/player.html?bvid=BV1kx411Q7kT&page=1", // 视频4链接
                title: "视频4标题"
            },
            {
                image: "https://picsum.photos/400/300?random=5", // 图片5路径
                video: "https://player.bilibili.com/player.html?bvid=BV1zs411c79C&page=1", // 视频5链接
                title: "视频5标题"
            },
            {
                image: "https://picsum.photos/400/300?random=6", // 图片6路径
                video: "https://player.bilibili.com/player.html?bvid=BV1BW411u7th&page=1", // 视频6链接
                title: "视频6标题"
            },
            {
                image: "https://picsum.photos/400/300?random=7", // 图片7路径
                video: "https://player.bilibili.com/player.html?bvid=BV1Ss411N7HU&page=1", // 视频7链接
                title: "视频7标题"
            },
            {
                image: "https://picsum.photos/400/300?random=8", // 图片8路径
                video: "https://player.bilibili.com/player.html?bvid=BV1FJ411d7oF&page=1", // 视频8链接
                title: "视频8标题"
            }
        ];

        // 生成8个图片到页面
        const imageGrid = document.getElementById("imageGrid");
        mediaData.forEach((item, index) => {
            const imageItem = document.createElement("div");
            imageItem.className = "image-item";
            imageItem.innerHTML = `
                <img src="${item.image}" alt="图片${index+1}">
                <p>${item.title}</p>
            `;
            // 点击图片打开对应视频
            imageItem.onclick = () => openVideo(index);
            imageGrid.appendChild(imageItem);
        });

        // 打开视频弹窗
        function openVideo(index) {
            const videoModal = document.getElementById("videoModal");
            const videoIframe = document.getElementById("videoIframe");
            // 若用本地视频，替换下面的iframe代码为：
            // const videoPlayer = document.getElementById("videoPlayer");
            // videoPlayer.src = mediaData[index].video;
            // videoPlayer.play();
            
            videoIframe.src = mediaData[index].video; // 加载对应视频
            videoModal.style.display = "flex"; // 显示弹窗
        }

        // 关闭视频弹窗
        function closeVideo() {
            const videoModal = document.getElementById("videoModal");
            const videoIframe = document.getElementById("videoIframe");
            // 若用本地视频，替换为：document.getElementById("videoPlayer").pause();
            
            videoIframe.src = ""; // 清空视频，停止播放
            videoModal.style.display = "none"; // 隐藏弹窗
        }

        // 点击弹窗背景也能关闭
        document.getElementById("videoModal").onclick = (e) => {
            if (e.target === document.getElementById("videoModal")) {
                closeVideo();
            }
        };
    </script>
</body>
</html>
